﻿/*----------------------------------------------------------------------------------------
*
*  Copyright 2019, Gao Hai Hui, <fromzeropoint@126.com>.  All rights reserved.
*  https://gitee.com/helloworldghh/xoskit.git
*  Use of this source code is governed by a MIT license
*  that can be found in the License file.
*
----------------------------------------------------------------------------------------*/
#ifndef __XOS_COMPRESS_SRC_BZIP2_IMPL_H__
#define __XOS_COMPRESS_SRC_BZIP2_IMPL_H__

#include "../tools/head.h"

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

namespace xos_compress
{

	class bzip2_impl : public xos_stl::mem_item< xos::release_impl< bzip2_impl >, thread_lock >,
		public i_compress
	{
    public:
        typedef xos::release_impl< bzip2_impl > T;

    public:
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //

        static int get_addr( POOL *** pppPool, LIST *** pppList );

    public:
		bzip2_impl();
		~bzip2_impl();

	public:
		int un_compress( char * lpszDest, int nDestLen, int * lpnDestLen, const char * lpszSrc, int nSrcLen );
		int compress( char * lpszDest, int nDestLen, int * lpnDestLen, const char * lpszSrc, int nSrcLen, bool bLast );
        int un_compress( xos_box::i_buf * pDestBuf, xos_box::i_buf * pSrcBuf );
		int compress( xos_box::i_buf * pDestBuf, xos_box::i_buf * pSrcBuf, bool bLast );
        int un_compress( xos_box::i_list * pDestList, xos_box::i_list * pSrcList );
        int compress( xos_box::i_list * pDestList, xos_box::i_list * pSrcList );

	protected:
		int my_BZ2_bzBuffToBuffCompress( 
			char*         dest,
			unsigned int* destLen,
			char*         source,
			unsigned int  sourceLen,
			int           blockSize100k,
			int           verbosity,
			int           workFactor );
		int my_BZ2_bzBuffToBuffDecompress(
			char*         dest,
			unsigned int* destLen,
			char*         source,
			unsigned int  sourceLen,
			int           sml,
			int           verbosity );

	public:
		int init();
		int term();
	};
}

#endif // __XOS_COMPRESS_SRC_BZIP2_IMPL_H__
